// -------------------------------------------------------------------------
//    @FileName         :    NFIPlayerRedisModule.h
//    @Author           :    LvSheng.Huang
//    @Date             :    2012-12-15
//    @Module           :    NFIPlayerRedisModule
//
// -------------------------------------------------------------------------

#ifndef NFI_PLAYER_REDIS_MODULE_H
#define NFI_PLAYER_REDIS_MODULE_H

#include "NFIModule.h"
#include "NFComm/NFPluginModule/NFIAsyMysqlModule.h"
#include "NFComm/NFPluginModule/NFIAsyNoSqlModule.h"

class NFIPlayerDBModule
    : public NFIModule
{
public:
    virtual bool LoadPlayerDataFromRedis(const NFGUID& self) = 0;
    virtual bool SavePlayerDataToRedis(const NFGUID& self) = 0;

    template<typename BaseType>
    int SendAsynLoadPlayerDataFromMySql(const NFGUID& self,
                                        BaseType* pBaseType, void (BaseType::*handleReturnRsp)(const NFGUID&, const int, const std::vector<std::string>&, const std::vector<std::string>&, const std::string&), const std::string& strUseData)
    {
        const MYSQL_RETURN_VECKEY_VECVALUE_FUNCTOR mFunReturnVeckKeyValueRsp = std::bind(handleReturnRsp, pBaseType, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5);

        return SendAsynLoadPlayerDataFromMySql(self, mFunReturnVeckKeyValueRsp, strUseData);
    }

    template<typename BaseType>
    bool SendAsynLoadPlayerDataFromRedis(const NFGUID& self,
                                         BaseType* pBaseType, void (BaseType::*handleReturnRsp)(const NFGUID&, NFMsg::PackNoSqlParam&, const std::string&))
    {
        const NOSQL_RETURN_FUNCTOR FunReturnRsp = std::bind(handleReturnRsp, pBaseType, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
        return SendAsynLoadPlayerDataFromRedis(self, FunReturnRsp) == 0;
    }

    virtual int SendAsynLoadPlayerDataFromMySql(const NFGUID& self, const MYSQL_RETURN_VECKEY_VECVALUE_FUNCTOR& mFunReturnVeckKeyValueRsp, const std::string& strUseData) = 0;
    virtual int SendAsynLoadPlayerDataFromRedis(const NFGUID& self, const NOSQL_RETURN_FUNCTOR& mFunReturnRsp) = 0;

    virtual int SendAsynSavePlayerDataToRedis(const NFGUID& self) = 0;
    virtual int SendAsynSavePlayerDataToMysql(const NFGUID& self) = 0;

    virtual int RecvAsynLoadPlayerDataFromRedis(const NFGUID& self, NFMsg::PackNoSqlParam& nosqlParam, const std::string& strUseData) = 0;
    virtual void RecvAsynLoadPlayerDataFromMysql(const NFGUID& self, const int nRet, const std::vector<std::string>& fieldVec, const std::vector<std::string>& valueVec, const std::string& strUseData) = 0;
};

#endif